﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElfTyping.States.GameState.Effects;
using ElfTyping.States.GameState.Entities;

namespace ElfTyping.States.GameState.PlayerPassives
{
    public class FrostArrowPassive : PlayerPassive
    {
        const int ProcChance = 75;
        const int SlowAmount = 30;
        const int SlowLengthSeconds = 4;

        public FrostArrowPassive()
        {
            Name = "Frost Arrow";
            Description = string.Format("{0}% chance to slow\nenemies you shoot by\n{1}% for {2} seconds.", ProcChance, SlowAmount, SlowLengthSeconds);
            CardImage = new Animations.Animation(@"textures\Cards\Passive_FrostArrow");
        }

        public override void OnShoot(GameScript script, Enemy enemy, bool wasPerfect)
        {
            if (random.Next(1, 101) <= ProcChance)
            {
                script.SpawnEffect(new FrostArrowEffect(enemy));
            }

            base.OnShoot(script, enemy, wasPerfect);
        }

        private class FrostArrowEffect : GameEffect
        {
            Enemy Enemy { get; set; }
            int OriginalSpeed { get; set; }

            public FrostArrowEffect(Enemy enemy)
            {
                Enemy = enemy;
                TimeLeft = SlowLengthSeconds;
            }

            public override void Tick(float dt)
            {
                if (Enemy.SpeedMultiplier > .7f)
                {
                    Enemy.SpeedMultiplier = .7f;
                }
                base.Tick(dt);
            }

            public override void OnEnd()
            {
                Enemy.SpeedMultiplier = 1f;

                base.OnEnd();
            }
        }
    }
}
